package agentspeakeditor.editors.highlight;

import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWhitespaceDetector;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.Token;

import agentspeakeditor.editors.ASLWhitespaceDetector;

public class BeliefRule implements IPredicateRule
{
	IWordDetector idDetector = new IDDetector();
	IToken fToken;
	
	public BeliefRule(IToken token) {
		this.fToken = token;
	}
	
	private int goToLastChar(ICharacterScanner scanner){
		int c = scanner.read();
		String tst = ""+(char)c;
		
		while(c != '.' && c != ICharacterScanner.EOF){			
			c = scanner.read();	
			tst = ""+(char)c;
		}
		
		return c;
	}

	@Override
	public IToken getSuccessToken() {
		return fToken;
	}

	@Override
	public IToken evaluate(ICharacterScanner scanner, boolean resume) {
		int c = scanner.read();
		String tst = ""+(char)c;
		
		if(idDetector.isWordStart((char)c)){
			c = goToLastChar(scanner);
			tst += ""+(char)c;
			
			if(c == '.' && scanner.read() == '\r')
				return (IToken) fToken;
		}
						
		return Token.UNDEFINED;
	}

	@Override
	public IToken evaluate(ICharacterScanner scanner) {
		return evaluate(scanner, false);
	}
	
	
	
}
